﻿#include <stdlib.h>
#include <stdio.h>

#include "carray.h"
#include "creader.h"
#include "carrayInt.h"
#include "cstring.h"


#define cplusplus_test 1
#if cplusplus_test
#include <fstream>
#include <vector>
#include <string>
#endif

int main()
{
	const char* filemane = "物品类型名.txt";

	cReader* reader = mallocReader(filemane, "rb");

	cArray* arrayInt = mallocArrayInt();

	bool isPrint = false;
	const char* c;
	while (true)
	{
		c = getNext(reader);
		if (!c)
		{
			break;
		}
		if (isPrint)
		{
			printf("\n");
		}
		// 换行
		if (isEnter(c))
		{

		}
		// 空格
		else if(isSpace(c))
		{

		}
		// 字符串 
		else
		{
			if (true)
			{
				// 转化int失败好像返回0
				int x = atoi(c);
				pushToArrayInt(arrayInt, x);
			}
		}
	}

	printf("\n");
	for (int k = 0; k < arrayInt->length; ++k)
	{
	//	break;
		printf("%d,", getElementInt(arrayInt, k));
	}
	printf("\n%d\n", arrayInt->length);

#if cplusplus_test
	std::ifstream ifile(filemane);
	std::string value;
	std::vector<std::string> values;
	while (ifile >> value)
	{
		values.push_back(value);
	}
	printf("\n%d\n", values.size());
#endif


	// 记得释放
	freeReader(reader);
	freeArray(arrayInt);

	if (true)
	{
		// 测试字符组
		cArray* arrayString = mallocString();

		resetString(arrayString, "\n呵呵哒");
		insertToString(arrayString, 1, "狼宝123");
		pushToString(arrayString, "ABC\n");

		printf(toChar(arrayString));
		freeArray(arrayString);
	}

	printf("\n按任意键继续...");
	for (;;);
}